package com.example.smart_city_0829.activity.digitallibrary;

import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.digitalLibrary.Library;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;

import retrofit2.Call;
import retrofit2.Response;

public class DigitalLibraryDetailActivity extends BaseActivity {

    private ImageView im;
    private Toolbar tool;
    private TextView title;
    private TextView subtitle;
    private TextView content;
    private TextView tag1;
    private TextView tag2;
    private TextView tag3;
    private Button comment;

    private Library.DataBean dataBean;

    private int id = -1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_digital_library_detail;
    }

    @Override
    protected void initView() {
        im = (ImageView) findViewById(R.id.im);
        tool = (Toolbar) findViewById(R.id.tool);
        title = (TextView) findViewById(R.id.title);
        subtitle = (TextView) findViewById(R.id.subtitle);
        content = (TextView) findViewById(R.id.content);
        tag1 = (TextView) findViewById(R.id.tag1);
        tag2 = (TextView) findViewById(R.id.tag2);
        tag3 = (TextView) findViewById(R.id.tag3);
        comment = findViewById(R.id.comment);
    }

    @Override
    protected void initData() {
        id = getIntent().getIntExtra("id", -1);

        setSupportActionBar(tool);
        tool.setTitle("正在加载中...");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        api.getLibraryDetail(id)
                .enqueue(new NetCallBack<Library>() {
                    @Override
                    public void onResponse(Call<Library> call, Response<Library> response) {
                        dataBean = response.body().getData();
                        //图片你拿不到
                        Glide.with(DigitalLibraryDetailActivity.this)
                                .load(Constant.BASE_URL + dataBean.getImgUrl())
                                .into(im);
                        tool.setTitle(dataBean.getName());
                        title.setText(dataBean.getName());
                        subtitle.setText("详细地址：" + dataBean.getAddress());
                        content.setText("介绍："+dataBean.getDescription());
                        tag1.setText("营业状态："+(dataBean.getBusinessState().equals("0") ? "暂停营业" : "正在营业"));
                        tag2.setText("营业时间："+dataBean.getBusinessHours());
                    }
                });
    }

    @Override
    protected void initEvent() {
        comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (id != -1){
                    final Intent intent = new Intent(DigitalLibraryDetailActivity.this, LibraryCommentActivity.class);
                    intent.putExtra("id",id);
                    startActivity(intent);
                }else {
                    showToastShort("正在加载中，请稍等...");
                }
            }
        });
    }

    @Override
    protected String getActionBarTitle() {
        return null;
    }
}